﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
///UserPrivilege 的摘要说明
/// </summary>
public struct AsUser 
{
    string username;
    int usermgr;
    int bbsmgr;
    int newsmgr;
    int sourcemgr;
    int upload;
    int download;
    int srccommentmgr;
    public string GetUserName()
    {
        return username;
    }
    public int GetUsermgrPrivilege()
    {
        return usermgr;
    }
    public int GetbbsmgrPrivilege()
    {
        return bbsmgr;
    }
    public int GetnewsmgrPrivilege()
    {
        return newsmgr;
    }
    public int GetsourcemgrPrivilege()
    {
        return sourcemgr;
    }
    public int GetuploadPrivilege()
    {
        return upload;
    }
    public int GetdownloadPrivilege()
    {
        return download;
    }
    public int GetsrccommPrivilege()
    {
        return srccommentmgr;
    }
    public void SetData(string un, int usmgr, int asbbsmgr, int asnewsmgr, int srcmgr, int upl, int downl, int srccommmgr)
    {
        username = un;
        usermgr = usmgr;
        bbsmgr = asbbsmgr;
        newsmgr = asnewsmgr;
        sourcemgr = srcmgr;
        upload = upl;
        download = downl;
        srccommentmgr = srccommmgr;
    }

}
public class UserPrivilege : System.Web.UI.Page
{
    public AsUser UserSession;
	public UserPrivilege()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
        if (Session["user"]!=null)
        {
            UserSession = (AsUser)Session["user"];
        } 
	}
    public void SetUserSession(string username,string userprivilege)
    {
        MysqlHelp assql = new MysqlHelp();
        string conn = string.Format("select * from syslimit where id='{0}'", userprivilege);
        DataTable dt = assql.GetDatabysql(conn);
        int asusermgr =(int) dt.Rows[0]["usermgr"];
        int asbbsmgr = (int)dt.Rows[0]["bbsmgr"];
        int asnewsmgr = (int)dt.Rows[0]["newsmgr"];
        int assourcemgr = (int)dt.Rows[0]["sourcemgr"];
        int asupload = (int)dt.Rows[0]["upload"];
        int asdownload = (int)dt.Rows[0]["download"];
        int assrccommentmgr = (int)dt.Rows[0]["srccommentmgr"];
        UserSession.SetData(username, asusermgr, asbbsmgr, asnewsmgr, assourcemgr, asupload, asdownload, assrccommentmgr);
        Session["user"] = UserSession;
    }
    /// <summary>
    /// 返回登录的用户名
    /// </summary>
    /// <returns></returns>
    public string GetSessionName()
    {
        return UserSession.GetUserName();
    }
   /// <summary>
   /// 返回是否具有用户管理的权限
   /// </summary>
   /// <returns></returns>
    public bool IsUsermgrPrivilege()
    {
        return (UserSession.GetUsermgrPrivilege() == 1 ? true : false);
    }
    /// <summary>
    /// 返回是否具有BBS管理的权限
    /// </summary>
    /// <returns></returns>
    public bool IsBBSmgrPrivilege()
    {
        return (UserSession.GetbbsmgrPrivilege() == 1 ? true : false);
    }
    /// <summary>
    /// 返回是否具有新闻管理的权限
    /// </summary>
    /// <returns></returns>
    public bool IsNewsmgrPrivilege()
    {
        return (UserSession.GetnewsmgrPrivilege() == 1 ? true : false);
    }
    /// <summary>
    /// 返回是否具有资源管理的权限
    /// </summary>
    /// <returns></returns>
    public bool IsSourcemgrPrivilege()
    {
        return (UserSession.GetsourcemgrPrivilege() == 1 ? true : false);
    }
    /// <summary>
    /// 返回是否具有上传的权限
    /// </summary>
    /// <returns></returns>
    public bool IsUpLoadPrivilege()
    {
        return (UserSession.GetuploadPrivilege() == 1 ? true : false);
    }
    /// <summary>
    /// 返回是否具有下载的权限
    /// </summary>
    /// <returns></returns>
    public bool IsDownLoadPrivilege()
    {
        return (UserSession.GetdownloadPrivilege() == 1 ? true : false);
    }
    /// <summary>
    /// 返回是否具有资源评论管理的权限
    /// </summary>
    /// <returns></returns>
    public bool IsSrcCommmgrPrivilege()
    {
        return (UserSession.GetsrccommPrivilege() == 1 ? true : false);
    }
}
